#ifndef PROGRAMRUN_H
#define PROGRAMRUN_H

#include <QWidget>
#include "ui_ProgramRun.h"
#include <QJsonObject>
#include <QThread>
#include "runerr.h"



enum
{
    E_STA_NONE = 0,
    E_STA_RUNNING,
    E_STA_FAIL,
    E_STA_SUCC,
};

typedef struct
{
    QString StrFlag;
    QString StrCmd;
    QJsonObject JsonObj;
    QString StrDetail;
    QString StrLevelLower;
    QString StrLevelUpper;
    QString StrUnit;
}T_program_Unit;

class ProGramRunThread : public QThread
{
    Q_OBJECT
public:
    ProGramRunThread(quint32 rowtotal, QList <T_program_Unit > tProgram,QObject *parent = nullptr);
    ~ProGramRunThread(void);
    void ProGramStop(void);
    void setErrRetFlag(quint8 flag);
public slots:
    void onDealRun(void);
signals:
    void sigRowSta(quint32 Row,quint8 Sta);//显示行状态
    void sigFailSet(QString str);//显示失败原因
    void sigRetValueSet(quint32 Row ,QString QStr);//设置值
private:
    QJsonObject PlugInRun(QString Label,QJsonObject qjson);
    void        sPlugInJudge(quint32 row,QJsonObject obj);
    quint8      Compare_int(QString Upper,QString Lower,qint32 Value);
    quint8      Compare_uint(QString Upper,QString Lower,quint32 Value);
    quint8      Compare_float(QString Upper,QString Lower,quint32 Value);
    quint8      Compare_hex(QString Upper,QString Lower,quint32 Value);
private:
    quint8 stopFlag;
    quint32 _rowtotal;
    quint32 _rowindex;
    quint32 _lastRowIndex;
    QList <T_program_Unit > _JsonList;
    quint8 sigFailRet;
};

class ProGramRun :public QWidget
{
    Q_OBJECT
public:
    ProGramRun(QWidget *parent = nullptr);
    void ProGramRum_Add(T_program_Unit *pUnit);
protected:
    void closeEvent(QCloseEvent *ev);
public slots:
    void onDealBegin(void);
    void onDealRowStaSet(quint32 Row,quint8 Sta);
    void onDealSetFailReason(QString str);
    void onDealErrRet(quint8 flag);
signals:
    void operate(void);
private:
    Ui::ProgramRun *_ui;
    QList <T_program_Unit >tProgram;

    ProGramRunThread *_ProThread;
    QThread           *_thread;
    RunErr            *_err ;

private:

};

#endif // PROGRAMRUN_H
